package service.local.beans;

import java.util.List;

import javax.ejb.DependsOn;
import javax.ejb.EJB;
import javax.ejb.Stateless;

import model.Comment;
import model.Interview;
import repository.InterviewRepository;
import repository.exceptions.RepositoryException;
import service.ServiceException;
import service.local.InterviewService;
@Stateless (name = "InterviewService", mappedName = "InterviewService")
@DependsOn ({"InterviewRepository"})
public class InterviewServiceBean implements InterviewService {
	
	@EJB
	InterviewRepository repo;
	@Override
	public Interview insertInterview(Interview Interview){
		Interview r=new Interview();
		try {
			return repo.save (Interview);
		} catch (final RepositoryException ex) {
			//throw new ServiceException("Insert Interview failed", ex);
		}
		return r;
	}

	@Override
	public Interview updateInterview(Interview Interview){
		try {
			repo.merge(Interview);
			return Interview;
		} catch (RepositoryException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
	}

	@Override
	public void deleteInterview(Interview Interview){
		try {
			repo.delete(Interview);
		} catch (RepositoryException e) {
			
		}
	}

	@Override
	public List<Interview> getAll(){
		try {
			return repo.getAll();
		}catch(final RepositoryException ex) {
			
		}
		return null;
	}

	@Override
	public void addCommentToInterview(Long id, Comment c)
			 {
		try {
			repo.addCommentToInterview(id, c);
		}catch(final RepositoryException ex) {
			
		}
		
	}

	@Override
	public List<Comment> getCommentsFromInterview(Long id)
			{
		try {
			return repo.getCommentsFromInterview(id);
		}catch(final RepositoryException ex) {
		
		}
		return null;
	}
	
	



}
